package org.wbd.pklib.db;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;
import java.util.HashSet;
import java.util.Set;

/**
 * Klasa reprezentująca obiekt uzytkownika,obiekt tej klasy jest obiektowym odzwierciedleniem
 * rekord w tabeli "user"
 */
@Entity
@Table(name = "user")
public class User implements java.io.Serializable{
	private Integer userId;
	private String name;
	private String surname;
	private String login;
	private String password;
	private String email;
	private String function;
	private Set<Item> items = new HashSet<Item>(0);
	private Set<RepoUser> repoUsers = new HashSet<RepoUser>(0); //repo - user associations
	
	
	public User() {
	}

	public User(Integer userId, String name, String surname, String login,
			String password, String email, String function) {
		this.userId = userId;
		this.name = name;
		this.surname = surname;
		this.login = login;
		this.password = password;
		this.email = email;
		this.function = function;
	}

	public User(Integer userId, String name, String surname, String login,
			String password, String email, String function, Set<Item> items, Set<RepoUser> repoUsers ) {
		this.userId = userId;
		this.name = name;
		this.surname = surname;
		this.login = login;
		this.password = password;
		this.email = email;
		this.function = function;
		this.items = items;
		this.repoUsers = repoUsers;		
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "userId", unique = true, nullable = false)
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@Column(name = "name", nullable = false, length = 32)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "surname", nullable = false, length = 32)
	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	@Column(name = "login", nullable = false, unique = true, length = 32)
	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	@Column(name = "password", nullable = false,  length = 32)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "email", nullable = true, length = 64)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "function", nullable = false, length = 32)
	public String getFunction() {
		return function;
	}

	public void setFunction(String function) {
		this.function = function;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "itemJoin.user",  cascade=CascadeType.ALL)
	public Set<Item> getItems() {
		return items;
	}

	public void setItems(Set<Item> items) {
		this.items = items;
	}	
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "repoUserJoin.user",  cascade=CascadeType.ALL)
	public Set<RepoUser> getRepoUsers() {
		return repoUsers;
	}

	public void setRepoUsers(Set<RepoUser> repoUsers) {
		this.repoUsers = repoUsers;
	}
	
	


	@Override
	public String toString() {
		return "User [userId=" + userId + ", name=" + name + ", surname="
				+ surname + ", login=" + login + ", password=" + password
				+ ", email=" + email + ", function=" + function + ", items="
				+  "]";
	}
	
	
	
	
}
